import Api from '../../api'
export default{

    state:{
        stadiumListData:{},
        stadiumListDataById:[],
    },
    actions:{
        // 获取球馆信息(分页)
        async getStadiumData({commit},pagination){
            const {data:res} = await Api.getStadiumList(pagination);
            if(res.status == 200) {
                commit("GETSTADIUMDATA",res.data);
            }
            return new Promise((resovle,reject)=>{
                if(res.status == 200) resovle(true)
                reject(false)
            })
        },
        // 根据sid获取球馆信息，如果没输入sid参数则获取所有数据
        async getStadiumDataById({commit},sid){
            const {data:res} = await Api.getStadiumListById(sid);
            if(res.status == 200){
                commit("GETSTADIUMDATABYID",res.data);
            }
            return new Promise((resovle,reject)=>{
                if(res.status == 200) resovle(true)
                reject(false)
            })
        },
        // 关键字查找
        async searchStadium({commit},query){
            const {data:res} = await Api.searchStadium(query);
             if(res.status == 200) {
                 commit("GETSTADIUMDATA",res.data)
             }
           },
    },
    mutations:{
        // 获取球馆信息
        GETSTADIUMDATA(state,stadiumListData){
            state.stadiumListData = stadiumListData;
        },
        GETSTADIUMDATABYID(state,stadiumListDataById){
            state.stadiumListDataById = stadiumListDataById;
        },
    
    },
    getters:{
        stadiumListData(state){
            return state.stadiumListData || {};
        },
        stadiumListDataById(state){
            return state.stadiumListDataById || [];
        }
    }
}